<%--
  Created by IntelliJ IDEA.
  User: fengdefangxiang
  Date: 2022/2/9
  Time: 17:30
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
    <%@ include file="/web/header.jsp" %>
</head>
<body>
<div class="layui-collapse">
    <div class="layui-colla-item">
        <h2 class="layui-colla-title">项目信息-查询条件</h2>
        <div class="layui-colla-content layui-show">

            <fieldset class="layui-elem-field layui-field-title" style="margin: 10px">
                <legend>绩效信息-查询条件</legend>
                <div class="layui-field-box">
                    <form class="layui-form">
                        <div class="layui-form-item">
                            <label class="layui-form-label">员工</label>
                            <div class="layui-input-inline">
                                <select name='name'></select>
                            </div>
                            <label class="layui-form-label">项目</label>
                            <div class="layui-input-inline">
                                <select name='prname'></select>
                            </div>
                            <label class="layui-form-label"></label>
                            <span>
                            <input type="button" value="查询" class="layui-btn layui-btn-radius" lay-submit
                                   lay-filter="search">
                            <input type="reset" class="layui-btn layui-btn-radius  layui-btn-primary"/>
                            <input type="button" class="layui-btn layui-btn-radius layui-btn-normal" onclick="openAdd()"
                                   value="添加"/>
                        </span>
                            <input type="hidden" name="action" value="page">
                            <input type="hidden" name="pageIndex" value="1">
                            <%--                      分页条件      第几页--%>
                            <input type="hidden" name="pageLimit" value="10">
                            <%--                            每页显示几条记录--%>

                        </div>
                    </form>
                </div>
            </fieldset>
        </div>
    </div>
</div>
<table class="layui-table" style="background: rgba(255, 194, 194, 0)">

    <colgroup>
        <col width="10%">
        <col width="15%">
        <col width="15%">
        <col width="15%">
        <col width="15%">
        <col width="15%">
        <col width="15%">
        <col>
    </colgroup>
    <thead>
    <tr>
        <th>序号</th>
        <th>员工编号</th>
        <th>员工姓名</th>
        <th>项目编号</th>
        <th>项目名称</th>
        <th>绩效</th>
        <th>操作</th>
    </tr>
    </thead>
    <tbody></tbody>
</table>
<div id="pageInfo" style="text-align: right;padding-right:30px"></div>
<script type="text/javascript">
    initSel();
    initSel2();

    function initSel() {//从数据库初始化下拉框中的数据
        ajax('/EmployeeServlet', {action: 'list'}, 'json', function (data) {
            var opt = "<option value=''>请选择员工</option>"
            $.each(data, function () {
                opt += "<option value='" + this.code + "'>" + this.name + "</option>"
            })
            $("select[name='name']").html(opt);
            form.render()
        })
    }

    function initSel2() {
        ajax('/ProjectServlet', {action: 'list'}, 'json', function (data) {
            console.log(data)
            var opt = "<option value=''>请选择项目</option>"
            $.each(data, function () {
                opt += "<option value='" + this.code + "'>" + this.name + "</option>"
            })
            $("select[name='prname']").html(opt);
            form.render()
        })

    }

    formOnSubmit('search', '/ScoreServlet', 'json', function (data) {
        console.log(data)
        // var count = data.count;
        //分页控件渲染=表格中全部数据的条数
        var curr = $("input[name='pageIndex']").val();
        var limit = $("input[name='pageLimit']").val();
        pageInfo('pageInfo', data.count, curr, limit, function (obj, first) {
            $("input[name='pageIndex']").val(obj.curr);//将数据重新填回表单
            $("input[name='pageLimit']").val(obj.limit);
            if (!first) {
                refresh();
            }//首次不执行
        });
        //展示表格的数据=表格中的当前页面的数据
        var html = "";
        var tpl = $("#tradd").html();
        $.each(data.list, function (i, dom) {
            dom.i = i + 1 + (curr - 1) * limit;
            // var d = {id: (i+1+(curr-1)*limit), code: dom.code, name: dom.name, time: dom.time}
            html += laytpl(tpl).render(dom);
        })
        $("tbody").html(html);//将数据传入html
        layer.msg("查询成功")
    })

    function refresh() {
        // $("input[type='reset']").click();
        $("input[value='查询']").click();
    }

    refresh();

    function openAdd() {
        layerOpen('/web/page/score/add.jsp', refresh);//回调方法 成功后重新查询列表
    }

    function del(codePro, codeEmp) {
        layerConfirm(function (index) {
            ajax("/ScoreServlet", {codePro: codePro, codeEmp: codeEmp, action: 'del'}, 'text', function (data) {
                if (data == 1) {
                    layer.msg("删除成功", refresh())
                } else {
                    layer.msg("删除失败")
                }
            })
        })
    }

    function openupd(codePro, codeEmp) {
        layerOpen('/web/page/score/upd.jsp?codeEmp=' + codeEmp + '&codePro=' + codePro, refresh);//ajax请求
        // layerOpen('/DepartmentServlet?action=get2?code='+code,refresh);//请求转发
    }
</script>
<script type="text/html" id="tradd">//模板方法
<tr>
    <td>{{d.id}}</td>
    <td>{{d.codeEmp}}</td>
    <td>{{d.empName}}</td>
    <td>{{d.codePro}}</td>
    <td>{{d.proName}}</td>
    <td>{{d.score}}</td>
    <%--    <td>{{d.count}}</td>--%>
    <td>
        <a href="javascript:del('{{d.codePro}}','{{d.codeEmp}}')" class="layui-btn layui-btn-sm layui-btn-danger">
            <i class='layui-icon layui-icon-delete'></i>
        </a>
        <a href="javascript:openupd('{{d.codePro}}','{{d.codeEmp}}')" class="layui-btn layui-btn-sm">修改</a>
    </td>
</tr>

</script>
</body>
</html>
